﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Printing;

namespace QSHC.QSchedule.Silverlight.Views
{
    public partial class AppointmentCardWindow : ChildWindow
    {
        private PrintDocument _printer;

        public AppointmentCardWindow()
        {
            InitializeComponent();

            _printer = new PrintDocument();
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            _printer.PrintPage += new EventHandler<PrintPageEventArgs>(PrintPage);
            _printer.Print("Print AppointmentCard");
        }

        private void PrintPage(object sender, PrintPageEventArgs e)
        {
            CompositeTransform cmpt = new CompositeTransform
            {
                ScaleX = 1.75,
                ScaleY = 1.75,
                TranslateX = 50,
                TranslateY = 50
            };

            var printOutput = new AppointmentCard();
            printOutput.DataContext = AppointmentCard.DataContext;
            printOutput.RenderTransform = cmpt;

            e.PageVisual = printOutput;
            //e.HasMorePages = i++ < 3;
        }

        private void PrintStickButton_Click(object sender, RoutedEventArgs e)
        {
            string s = "Cost Bla Bla Bla.....";

            PrintDocument p = new PrintDocument();
            p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
            {
                //e1.Graphics.DrawString(s, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
            };
            try
            {
                //p.Print();
            }
            catch (Exception ex)
            {
                throw new Exception("Exception Occured While Printing", ex);
            }
        }
    }
}

